
using Catalog.Application.Brands.Interfaces;
using Catalog.Domain.Entities;
using Microsoft.EntityFrameworkCore;

namespace Catalog.Infrastructure.Repositories;

public class BrandRepository : IBrandRepository
{
    private readonly CatalogDbContext _dbContext;
    public BrandRepository(CatalogDbContext dbContext)
    {
        _dbContext = dbContext;
    }

    public void Add(Brand entity)
    {
        _dbContext.Brands.Add(entity);
    }


    public Task<Brand?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
    {
        return _dbContext.Brands
            .FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
    }

    public void Remove(Brand entity)
    {
        _dbContext.Brands.Remove(entity);
    }
}